package top.xin1901.j2ecd.beans;

import lombok.Data;
import top.xin1901.j2ecd.beans.dbo.GroupDbO;
import top.xin1901.j2ecd.beans.dbo.RoleDbO;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author HeYunjia
 */

@Data
public class Group {
    private Long groupId;
    private String groupName;
    private String groupComment;
    private Date gmtCreate;
    private Date gmtModified;

    private List<RoleDbO> roles;

    public GroupDbO toGroupDbO() {
        GroupDbO groupDbO = new GroupDbO();

        groupDbO.setGroupName(this.getGroupName());
        groupDbO.setGroupComment(this.getGroupComment());
        groupDbO.setGmtCreate(this.getGmtCreate());
        groupDbO.setGmtModified(this.getGmtModified());

        return groupDbO;
    }

    public List<Long> toRoleIds() {
        List<Long> roleIds = new ArrayList<>();

        for (RoleDbO roleDbO : this.getRoles()) {
            roleIds.add(roleDbO.getRoleId());
        }

        return roleIds;
    }
}
